package com.jason.game.online

import android.app.Application
import android.content.Context
import com.cby.library.common.GlobalApp
import com.cby.library.tool.CbyTools
import com.cby.library.tool.crash.CrashListener
import com.cby.library.tool.crash.CrashManager
import com.cby.library.tool.crash.CrashUtils
import com.cby.library.tool.util.CbyLogUtils
import com.cby.library.tool.log.CbyLogManager

class MyApp : Application() {



    override fun onCreate() {
        super.onCreate()

        GlobalApp.application = this

        CbyTools.init(this)
        CbyTools.setFloat(this)

        CrashManager.getInstance().setCrashLocal()
        CrashManager.getInstance().init(
            this,
            object : CrashListener {

                override fun againStartApp() {
                    //通过开启服务延迟app重启
                    //CrashUtils.restartAppWithDelay(this@MyApp, 2000)
                    //指定app重启 延迟多久重启，并且重启后，打开某个页面
                    CrashUtils.restartAppFromTargetActivity(this@MyApp, 2000, MainActivity::class.java)
                    //直接重启App
                    //CrashUtils.restartAppFromCurrentActivity(this@MyApp)
                }

                override fun recordException(ex: Throwable?) {
                    // 这边可以做其他的异常相关的处理操作
                }
            }
        )
        CbyLogManager.instance.addLogTag(CbyLogUtils.DEFAULT_TAG,"V")
        CbyLogManager.instance.addLogTag(CbyLogUtils.PREFIX_TAG+CbyLogUtils.DEFAULT_TAG, "I")
        CbyLogManager.instance.setAll(false)
        CbyLogManager.instance.init(this)
    }

    init {
        mContext = this
    }



    companion object {
        lateinit var mContext: Context

        @JvmStatic
        fun isPreviewMode(): Boolean{
            return false
        }
    }
}